import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author: gao
 * @create-date: 2025/3/25 20:44
 */

public class Solution {
    public int subarraysDivByK(int[] nums, int k) {
        Map<Integer, Integer> hash = new HashMap<>();
        hash.put(0 % k, 1);

        int sum = 0, ret = 0;
        for (int x : nums) {
            sum += x;
            int r = (sum % k + k) % k;
            ret += hash.getOrDefault(r, 0);//统计结果
            hash.put(r, hash.getOrDefault(r, 0) + 1);
        }
        return ret;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int len = in.nextInt();
            int[] nums = new int[len];
            for (int i = 0; i < len; i++) {
                nums[i] = in.nextInt();
            }
            int k = in.nextInt();
            Solution solution = new Solution();
            System.out.println(solution.subarraysDivByK(nums, k));
        }
    }
}